package com.gitee.starblues.example.basic1.service.listener;

import com.gitee.starblues.bootstrap.realize.PluginCloseListener;
import com.gitee.starblues.core.PluginCloseType;
import com.gitee.starblues.core.PluginInfo;
import com.gitee.starblues.core.descriptor.PluginDescriptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.stereotype.Component;

/**
 * 插件关闭监听
 *
 * @author starBlues
 * @version 1.0
 * @date 2022-08-26
 */
@Component
public class MyCloseListener implements PluginCloseListener {

    @Autowired
    private PluginInfo pluginInfo;

    @Override
    public void close(GenericApplicationContext applicationContext, PluginInfo pluginInfo, PluginCloseType closeType) {
        if(closeType == PluginCloseType.UNINSTALL){
            System.out.println("插件被卸载了：" + pluginInfo.getPluginId());
        } else if(closeType == PluginCloseType.STOP){
            System.out.println("插件被关闭了：" + pluginInfo.getPluginId());
        } else if(closeType == PluginCloseType.UPGRADE_UNINSTALL){
            System.out.println("插件被升级卸载了：" + pluginInfo.getPluginId());
        }
        System.out.println("注入的插件信息：" + pluginInfo.getExtensionInfo());
    }
}
